/* vim: set ts=2 et sw=2 cindent fo=qroca: */

package com.globant.google.mendoza.command;

/** Represents the mendoza server command result.
 */
public final class MendozaCommandResult {

  /** True if the command did not succeed. */
  private boolean error;

  /** The result message. */
  private String message;

  /** Sets the result as an error.
   *
   * @param errorMessage The result message.
   */
  public void setError(final String errorMessage) {
    error = true;
    message = errorMessage;
  }

  /** Sets the result as a success.
   *
   * @param theMessage The result message.
   */
  public void setSuccess(final String theMessage) {
    error = false;
    message = theMessage;
  }

  /** Gets the result message.
   *
   * @return Returns the result message.
   */
  public String getMessage() {
    return message;
  }

  /** True if the command did not succeed.
   *
   * @return Returns true if the command did not succeed.
   */
  public boolean isError() {
    return error;
  }

  /** String representation of command result.
   *
   * @return Returns the command result description.
   */
  public String toString() {
    StringBuffer sf = new StringBuffer();
    sf.append("\n");
    sf.append(getMessage());
    return sf.toString();
  }

  /** Decorates the command result.
   *
   * @param decorator The command decorator.
   *
   * @return Returns the decorated command result.
   */
  public String decorate(final DefaultResultDecorator decorator) {
    return decorator.decorate(this);
  }
}
